package com.fucius.study.leetcode;

import java.util.ArrayList;
import java.util.List;

public class MaxScore {
    public int maxScore(String s) {
        int n = s.length();
        int[] pre = new int[n];
        int[] suf = new int[n];
        pre[0] = '0'==s.charAt(0)?1:0;
        suf[n-1] = '1'==s.charAt(n-1)?1:0;

        int i=1,j=n-2;
        while(i<n){
            pre[i] = pre[i-1] + ('0'==s.charAt(i)?1:0);
            suf[j] = suf[j+1] + ('1'==s.charAt(j)?1:0);
            i++;
            j--;
        }

        int count = 0;
        for(i=0;i<n-1;i++){
            count = Math.max(count,pre[i]+suf[i+1]);
        }
        return count;
    }

    public static void main(String[] args) {
        System.out.println(new MaxScore().maxScore("011101"));
        List<Integer> ans = new ArrayList<>();

    }
}
